package com.shell.customer.base.rx;

import com.shell.bee.base.utils.JsonUtil;
import com.shell.bee.base.utils.SpringContextUtil;
import com.shell.customer.base.CusEvent;
import com.shell.customer.base.vo.CusRecVo;
import com.shell.customer.po.CusRec;
import com.shell.feign.ContractTransferFeigh;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.governor.user.vo.PubUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SyncEntUserSubscriber extends OnErrorNotImplementedSubscriber<CusEvent> {
	@Autowired
	private ContractTransferFeigh contractTransferFeigh;

	public void onApplicationEvent(CusEvent event) {
		if ("on".equals(SpringContextUtil.getProperty("contract.switch"))) {
			PubUserVo user = event.getUser();
			CusRecVo cusVo = event.getCusRecVo();
			CusRec cus = new CusRec();
			BeanUtils.copyProperties(cusVo, cus);
			String cusJson = null;
			String userJson = null;
			try {
				cusJson = JsonUtil.toJson(cus);
				userJson = JsonUtil.toJson(user);
			} catch (Exception e) {
				e.printStackTrace();
			}
			this.contractTransferFeigh.entUserSync(cusJson, userJson);
		}
	}
}
